<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="weaver.conn.RecordSet"%>
<%@page import="java.sql.Statement"%>
<%@ page import="com.alibaba.fastjson.*" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.sql.ResultSet" %>
<%
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json; charset=utf-8");
    JSONObject retObject = new JSONObject();
    retObject.put("code", 200);
    retObject.put("msg", "操作成功");
     
    try {
        // URL 参数
        Object userName = request.getParameter("userName");
        JSONArray array = new JSONArray();
        if(userName == null){
            retObject.put("code", -1);
            retObject.put("msg", "查询用户姓名不能为空");
        }else {
        	 String queryUserSql = "select    *    from HrmResource where   lastname = N'"+userName+"' ORDER BY ID DESC";
        	 RecordSet set0  = new RecordSet();
             set0.executeSql(queryUserSql);
             String departIds =""; 
             String jobIds = ""; 
             while(set0.next()){
			     JSONObject userObject = new JSONObject();
			     userObject.put("userId", set0.getString("loginid"));
			     userObject.put("userName", set0.getString("lastname"));
            	 String  deptid = set0.getString("departmentid");
            	 String queryDeptSql = "select top 1 * from HrmDepartment where id= '"+deptid+"' order by id DESC ";
            	 RecordSet set1 = new RecordSet();
                 set1.executeSql(queryDeptSql);
                 if(set1.next()){
                	 userObject.put("deptName", set1.getString("departmentname"));
                 }
            	 String jobId = set0.getString("jobtitle");
            	 String queryJobSql = "SELECT top 1 * FROM HrmJobTitles WHERE id = '"+jobId+"'  order by id DESC";
            	 RecordSet set2 = new RecordSet();
                 set2.executeSql(queryJobSql);
                 if(set2.next()){
                	 userObject.put("jobName", set2.getString("jobtitlename"));
                 }
                 array.add(userObject); 
             }
             retObject.put("data", array);
        }
    } catch (Exception e) {
        e.printStackTrace();
        retObject.put("code", -1);
        retObject.put("msg", e.getMessage());
    } finally {
        PrintWriter printWriter = response.getWriter();
        printWriter.append(retObject.toJSONString());
        if (printWriter != null)  printWriter.close();
    }
%>
 